﻿using Microsoft.Xna.Framework;
using WindowsGame.Manager;
using XnaContentManager = Microsoft.Xna.Framework.Content.ContentManager;

namespace WindowsGame
{
	/// <summary>
	/// GameManager is responsible for managing all game actions.
	/// </summary>
	public interface IGameManager
	{
		void Initialize(GraphicsDeviceManager graphics);
		void LoadContent(XnaContentManager content);
		void UnloadContent();
		void Update(GameTime gameTime);
		void Draw();
	}

	public class GameManager : IGameManager
	{
		private readonly ICameraManager cameraManager;
		private readonly IContentManager contentManager;
		private readonly IGameObjectManager gameObjectManager;
		private readonly IGraphicsManager graphicsManager;
		private readonly IScreenManager screenManager;

		public GameManager(
			ICameraManager cameraManager,
			IContentManager contentManager,
			IGameObjectManager gameObjectManager,
			IGraphicsManager graphicsManager,
			IScreenManager screenManager
			)
		{
			this.cameraManager = cameraManager;
			this.contentManager = contentManager;
			this.gameObjectManager = gameObjectManager;
			this.graphicsManager = graphicsManager;
			this.screenManager = screenManager;
		}

		// Initialize graphics and camera.
		public void Initialize(GraphicsDeviceManager graphics)
		{
			graphicsManager.Initialize(graphics);
			cameraManager.Initialize(new Vector3(0.0f, 50.0f, 5000.0f));
		}

		// Load all content.
		public void LoadContent(XnaContentManager content)
		{
			contentManager.LoadContent(content);
			gameObjectManager.LoadContent();
		}

		// Unload all content.
		public void UnloadContent()
		{
			contentManager.UnloadContent();
		}

		// Update each screen.
		public void Update(GameTime gameTime)
		{
			screenManager.Update(gameTime);
		}

		// Draw each screen.
		public void Draw()
		{
			screenManager.Draw();
		}
	}
}
